//
//  RootViewController.m
//  NewBook
//
//  Created by dlios on 15-3-7.
//  Copyright (c) 2015年 dlios. All rights reserved.
//

#import "RootViewController.h"

@interface RootViewController ()

@end

@implementation RootViewController
-(void)dealloc
{
    [_myPageC release];
    [_myScrollView release];
    [_myTimer release];
    [_scrollImageArray release];
    [_leftVC release];
    [_allFreeArray release];
    [_allPayArray release];
    [_allSaleArray release];
    [_showFreeArray release];
    [_showPayArray release];
    [_showSaleArray release];
    [super dealloc];
}
- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
//    self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
//    self.window.backgroundColor = [UIColor whiteColor];
    
    //在加载时显示动图
    //动图加载
    [GiFHUD setGifWithImageName:@"pika.gif"];
    [GiFHUD show];

    self.title = @"墨香书阁";
    self.view.backgroundColor = [UIColor grayColor];
    UIImageView *screenImageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height)];
    screenImageView.image = [UIImage imageNamed:@"bg1.png"];
        [self.view addSubview:screenImageView];
    
    [screenImageView release];
    //数组初始化
    self.allSaleArray = [NSMutableArray array];
    self.showSaleArray = [NSMutableArray array];
    self.allFreeArray = [NSMutableArray array];
    self.showFreeArray = [NSMutableArray array];
    self.allPayArray = [NSMutableArray array];
    self.showPayArray = [NSMutableArray array];
    //AFN请求特价优惠数据
    [AFNDownLoader getDataDownLoad:@"http://mapi.dangdang.com/index.php?action=list_category&user_client=iphone&client_version=5.0.1&page=5&page_size=10&sort_type=default_0&cid=01.01.00.00.00.00&img_size=h&udid=18948B21919333DDC1DDE273A67E5005&time_code=CAC30CE21A9B7F3ED5B12910AB91E139&timestamp=1425611852&union_id=537-50&permanent_id=20150304193014100686115327268485015" block:^(id myData) {
        //self.allMovieArray = [NSMutableArray array];
        //用一个大字典接收网络请求的数据
        NSMutableDictionary *saleDic = myData;
        //NSLog(@"000000=%@", saleDic);
  //取出productsArray数组
        NSMutableArray *productsArray = [saleDic objectForKey:@"products"];
        //NSLog(@"didian=%@", productsArray);
      //遍历数组productsArray下的每个小字典
        for (NSMutableDictionary *dic in productsArray) {
            BookSale *bookSale = [[BookSale alloc] init];
            bookSale.image_url = [dic objectForKey:@"image_url"];
            [bookSale setValuesForKeysWithDictionary:dic];
            bookSale.productId = [dic objectForKey:@"id"];
            [self.allSaleArray addObject:bookSale];
        }
        
        //NSLog(@"字典=%@", self.allSaleArray);
        
       // 循环取出特价优惠下的大数组,然后取出前三个添加到展示特价优惠数组中
        for (int i = 0; i < 5; i++) {
            BookSale *bookSale = [self.allSaleArray objectAtIndex:i];
            //NSLog(@"888=%@", bookSale.image_url);
            [self.showSaleArray addObject:bookSale];
           
        }
        
  //----------------------------------------------------------------
        //AFN请求免费阅读数据
        [AFNDownLoader getDataDownLoad:@"http://mapi.dangdang.com/index.php?action=list_category&user_client=iphone&client_version=5.0.1&page=5&page_size=10&sort_type=default_0&cid=01.03.00.00.00.00&img_size=h&udid=18948B21919333DDC1DDE273A67E5005&time_code=761902DD0FA78E7F15D36D3B0B71B6ED&timestamp=1425612507&union_id=537-50&permanent_id=20150304193014100686115327268485015" block:^(id myData) {
            //self.allMovieArray = [NSMutableArray array];
            //用一个大字典接收网络请求的数据
            NSMutableDictionary *FreeDic = myData;
            //NSLog(@"fdjkfh=%@", saleDic);
            NSMutableArray *productsArray = [FreeDic objectForKey:@"products"];
            
            for (NSMutableDictionary *dic in productsArray) {
                BookFree *bookFree = [[BookFree alloc] init];
                bookFree.image_url = [dic objectForKey:@"image_url"];
                [bookFree setValuesForKeysWithDictionary:dic];
                bookFree.productId = [dic objectForKey:@"id"];
                [self.allFreeArray addObject:bookFree];
            }
            
            
            
            // 循环取出特价优惠下的大数组,然后取出前三个添加到展示特价优惠数组中
            for (int i = 0; i < 5; i++) {
                BookFree *bookFree = [self.allFreeArray objectAtIndex:i];
               // NSLog(@"888=%@", bookFree.image_url);
                [self.showSaleArray addObject:bookFree];
                
            }

//----------------------------------------------------------------
            //AFN请求付费阅读数据
            [AFNDownLoader getDataDownLoad:@"http://mapi.dangdang.com/index.php?action=list_category&user_client=iphone&client_version=5.0.1&page=5&page_size=10&sort_type=default_0&cid=01.05.00.00.00.00&img_size=h&udid=18948B21919333DDC1DDE273A67E5005&time_code=E0C939B3237B81CE9A06E0FCDC64FB3A&timestamp=1425613446&union_id=537-50&permanent_id=20150304193014100686115327268485015" block:^(id myData) {
                //self.allMovieArray = [NSMutableArray array];
                //用一个大字典接收网络请求的数据
                NSMutableDictionary *PayDic = myData;
               // NSLog(@"fdjkfh=%@", saleDic);
                NSMutableArray *productsArray = [PayDic objectForKey:@"products"];
                
                for (NSMutableDictionary *dic in productsArray) {
                    BookPay *bookPay = [[BookPay alloc] init];
                    bookPay.image_url = [dic objectForKey:@"image_url"];
                    [bookPay setValuesForKeysWithDictionary:dic];
                    bookPay.productId = [dic objectForKey:@"id"];
                    [self.allPayArray addObject:bookPay];
                }
                
                
                
                // 循环取出特价优惠下的大数组,然后取出前三个添加到展示特价优惠数组中
                for (int i = 0; i < 5; i++) {
                    BookPay *bookPay = [self.allPayArray objectAtIndex:i];
                   // NSLog(@"888=%@", bookPay.image_url);
                    [self.showPayArray addObject:bookPay];
                    
                }

        
 //----------------------------------------------------------------
    //滚屏数组
    self.scrollImageArray = [NSMutableArray array];
    //从网络取出4张图片,加到数组中
    NSString *url1 = @"http://img3.ddimg.cn/00470/wuxiandacu/640-280.jpg";
    [self.scrollImageArray addObject:url1];
    NSString *url2 = @"http://img3.ddimg.cn/00470/daxiongdi3/nv640-280.jpg";
    [self.scrollImageArray addObject:url2];
    NSString *url3 = @"http://img3.ddimg.cn/00470/langxianping/640280.jpg";
    [self.scrollImageArray addObject:url3];
    NSString *url4 = @"http://img3.ddimg.cn/00470/chunjiezhoumo/changjia640-280.jpg";
    [self.scrollImageArray addObject:url4];
    //取出数组中第一个url
    NSString *firstURL = [self.scrollImageArray firstObject];
    //NSLog(@"1.%@", firstURL);
    //取出数组中最后一个url
    NSString *lastURL = [self.scrollImageArray lastObject];
    
    //把第一个url插入到数组中最后
    [self.scrollImageArray addObject:firstURL];
    //把最后一个url插入到数组中下标为0的位置
    [self.scrollImageArray insertObject:lastURL atIndex:0];
    
    //自动滚屏
    self.myScrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, 160)];
    //设置滚屏大小
    self.myScrollView.contentSize = CGSizeMake(self.view.frame.size.width * 6, 0);
    //设置默认显示的是数组中的第二页
    [self.myScrollView setContentOffset:CGPointMake(self.view.frame.size.width, 0) animated:YES];
    
    //单页滚动
    self.myScrollView.pagingEnabled = NO;
    //边缘处是否有反弹效果
    self.myScrollView.bounces = NO;
    self.myScrollView.backgroundColor = [UIColor yellowColor];
    self.myScrollView.delegate = self;
    [self.view addSubview:self.myScrollView];
    
    
    //在滚动屏上建6个imageView
    for (int i = 0; i < 6; i++) {
        UIImageView *imageV = [[UIImageView alloc]initWithFrame:CGRectMake(self.view.frame.size.width * i, 0, self.view.frame.size.width, self.myScrollView.frame.size.height)];
        imageV.tag = 1000 + i;
        //取出imageArray数组下每个url对象
        NSString *urlStr = [self.scrollImageArray objectAtIndex:i];
        NSURL *url = [NSURL URLWithString:urlStr];
        //加载图片
        [imageV sd_setImageWithURL:url placeholderImage:[UIImage imageNamed:@"picholder.png"]];
        [self.myScrollView addSubview:imageV];
    }
    
    
    //小点点
    self.myPageC = [[UIPageControl alloc] initWithFrame:CGRectMake(self.view.frame.size.width - 120, self.myScrollView.frame.size.height - 30, 120, 30)];
    self.myPageC.backgroundColor = [UIColor clearColor];
    self.myPageC.currentPage = 1;
    self.myPageC.numberOfPages = 4;
    self.myPageC.pageIndicatorTintColor = [UIColor grayColor];
    self.myPageC.currentPageIndicatorTintColor = [UIColor redColor];
    [self.view addSubview:self.myPageC];
    
    [self.myPageC addTarget:self action:@selector(pageIndexAction:) forControlEvents:(UIControlEventValueChanged)];
    
    //图片滚动的定时器
    self.myTimer = [NSTimer scheduledTimerWithTimeInterval:3 target:self selector:@selector(change) userInfo:nil repeats:YES];
    //------------------------------------------------------
    //定时器下面的布局
    
    //----------------特价优惠-----------------------------------------
    //特价优惠背景图片
    UIImageView *imageView1 = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"promotion_white_bg@2x.png"]];
    imageView1.frame = CGRectMake(0, self.myScrollView.frame.size.height, self.view.frame.size.width, 30);
    //打开imageView1的交互功能
    imageView1.userInteractionEnabled = YES;
    [self.view addSubview:imageView1];
    //特价优惠文字
    UILabel *lable1 = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, 30)];
    lable1.text = @"   特价优惠";
    lable1.textColor = [UIColor grayColor];
    [imageView1 addSubview:lable1];
    //特价优惠的更多按钮
    UIButton *button1 = [UIButton buttonWithType: UIButtonTypeCustom];
    [button1 setBackgroundImage:[UIImage imageNamed:@"btn_popup-data_n@2x.png"] forState:UIControlStateNormal];
    [button1 setTitle:@"更多" forState:UIControlStateNormal];
    button1.frame = CGRectMake(self.view.frame.size.width - 60, 0, 60, 30);
    [button1 setTitleColor:[UIColor grayColor] forState:UIControlStateNormal];
    [imageView1 addSubview:button1];
     //更多按钮触发的方法
    [button1 addTarget:self action:@selector(button1Action:) forControlEvents:UIControlEventTouchUpInside];
                
    //特价优惠下面的书架
    UIView *view1 = [[UIView alloc] initWithFrame:CGRectMake(0, 190, self.view.frame.size.width, 103)];
    [self.view addSubview:view1];
    UIImageView *bookShelfImageView1 = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"2.png"]];
               
    bookShelfImageView1.frame = CGRectMake(0, 0, self.view.frame.size.width, view1.frame.size.height);
    [view1 addSubview:bookShelfImageView1];
        [view1 release];
        [bookShelfImageView1 release];
    //循环,创建5张图片
    for (int i = 0; i < 5; i++) {
        //创建imageview用来存放书的图片
        UIImageView *bookSaleImageView = [[UIImageView alloc] initWithFrame:CGRectMake( i * 75, 0, 75, 87)];
                //取出展示数组下的每个对象
        //打开bookSaleImageView的交互功能
        bookSaleImageView.userInteractionEnabled = YES;
        bookSaleImageView.tag = 1001 + i;
        BookSale *bookSale = [self.showSaleArray objectAtIndex:i];
        
        NSURL *bookSaleUrl = [NSURL URLWithString:bookSale.image_url];
        //sd请求图片
        [bookSaleImageView sd_setImageWithURL:bookSaleUrl placeholderImage:[UIImage imageNamed:@"picLib_default@2x.png"]];
        [view1 addSubview:bookSaleImageView];
        //给每个图片添加一个轻拍手势
        UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapAction1:)];
        [bookSaleImageView addGestureRecognizer:tap];
        [tap release];
        [bookSaleImageView release];
        //NSLog(@"aaa=%@", bookSaleUrl);
    }
    
                
    
    
    //---------------------------免费阅读-------------------------------
    //免费阅读背景图片
    UIImageView *imageView2 = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"promotion_white_bg@2x.png"]];
    imageView2.frame = CGRectMake(0, self.myScrollView.frame.size.height + 133, self.view.frame.size.width, 30);
    //打开imageView2的交互功能
    imageView2.userInteractionEnabled = YES;
    [self.view addSubview:imageView2];
    //免费阅读文字
    UILabel *lable2 = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, 30)];
    lable2.text = @"   免费阅读";
    lable2.textColor = [UIColor grayColor];
    [imageView2 addSubview:lable2];
    
    //免费阅读的更多按钮
    UIButton *button2 = [UIButton buttonWithType: UIButtonTypeCustom];
    [button2 setBackgroundImage:[UIImage imageNamed:@"btn_popup-data_n@2x.png"] forState:UIControlStateNormal];
    [button2 setTitle:@"更多" forState:UIControlStateNormal];
    button2.frame = CGRectMake(self.view.frame.size.width - 60, 0, 60, 30);
    [button2 setTitleColor:[UIColor grayColor] forState:UIControlStateNormal];
    [imageView2 addSubview:button2];
    //更多按钮触发的方法
    [button2 addTarget:self action:@selector(button2Action:) forControlEvents:UIControlEventTouchUpInside];
        
        //免费阅读下面的书架
    UIView *view2 = [[UIView alloc] initWithFrame:CGRectMake(0, view1.frame.origin.y + view1.frame.size.height + lable1.frame.size.height, self.view.frame.size.width, 103)];
    [self.view addSubview:view2];
    UIImageView *bookShelfImageView2 = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"2.png"]];
    bookShelfImageView2.frame = CGRectMake(0, 0, self.view.frame.size.width, view1.frame.size.height);
    [view2 addSubview:bookShelfImageView2];
        [view2 release];
        [bookShelfImageView2 release];
            //NSLog(@"字典=%@", self.allFreeArray);
            //在书架上放图片
        //循环,创建5张图片
        for (int i = 0; i < 5; i++) {
            //创建imageview用来存放书的图片
            UIImageView *bookFreeImageView = [[UIImageView alloc] initWithFrame:CGRectMake( i * 75, 0, 75, 87)];
            //打开bookFreeImageView的交互功能
            bookFreeImageView.userInteractionEnabled = YES;
            bookFreeImageView.tag = 2001 + i;

            //取出展示数组下的每个对象
            BookFree *bookFree = [self.allFreeArray objectAtIndex:i];
            
            NSURL *bookFreeUrl = [NSURL URLWithString:bookFree.image_url];
            //sd请求图片
            [bookFreeImageView sd_setImageWithURL:bookFreeUrl placeholderImage:[UIImage imageNamed:@"picLib_default@2x.png"]];
            [view2 addSubview:bookFreeImageView];
            //给每个图片添加一个轻拍手势
            UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapAction2:)];
            [bookFreeImageView addGestureRecognizer:tap];
            [tap release];

            [bookFreeImageView release];
           // NSLog(@"aaa=%@", bookFreeUrl);
        }

    
    //--------------------------付费专区----------------------------
    //付费专区背景图片
    UIImageView *imageView3 = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"promotion_white_bg@2x.png"]];
    imageView3.frame = CGRectMake(0, self.myScrollView.frame.size.height + 266, self.view.frame.size.width, 30);
    //打开imageView3的交互功能
    imageView3.userInteractionEnabled = YES;
    [self.view addSubview:imageView3];
    //付费专区文字
    UILabel *lable3 = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, 30)];
    lable3.text = @"   付费专区";
    lable3.textColor = [UIColor grayColor];
    [imageView3 addSubview:lable3];
    
    //付费专区的更多按钮
    UIButton *button3 = [UIButton buttonWithType: UIButtonTypeCustom];
    [button3 setBackgroundImage:[UIImage imageNamed:@"btn_popup-data_n@2x.png"] forState:UIControlStateNormal];
    [button3 setTitle:@"更多" forState:UIControlStateNormal];
    button3.frame = CGRectMake(self.view.frame.size.width - 60, 0, 60, 30);
    [button3 setTitleColor:[UIColor grayColor] forState:UIControlStateNormal];
    [imageView3 addSubview:button3];
    //更多按钮触发的方法
    [button3 addTarget:self action:@selector(button3Action:) forControlEvents:UIControlEventTouchUpInside];
            
                
    //付费专区下面的书架
    UIView *view3 = [[UIView alloc] initWithFrame:CGRectMake(0, view2.frame.origin.y + view2.frame.size.height + lable2.frame.size.height, self.view.frame.size.width, 103)];
    [self.view addSubview:view3];
    UIImageView *bookShelfImageView3 = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"2.png"]];
    bookShelfImageView3.frame = CGRectMake(0, 0, self.view.frame.size.width, view1.frame.size.height);
    [view3 addSubview:bookShelfImageView3];
        [view3 release];
        [bookShelfImageView3 release];

            //在书架上放图片
            //循环,创建5张图片
            for (int i = 0; i < 5; i++) {
                //创建imageview用来存放书的图片
                UIImageView *bookPayImageView = [[UIImageView alloc] initWithFrame:CGRectMake( i * 75, 0, 75, 87)];
                //打开bookFreeImageView的交互功能
                bookPayImageView.userInteractionEnabled = YES;
                bookPayImageView.tag = 3001 + i;

                //取出展示数组下的每个对象
                BookPay *bookPay = [self.allPayArray objectAtIndex:i];
                
                NSURL *bookPayUrl = [NSURL URLWithString:bookPay.image_url];
                //sd请求图片
                [bookPayImageView sd_setImageWithURL:bookPayUrl placeholderImage:[UIImage imageNamed:@"picLib_default@2x.png"]];
                [view3 addSubview:bookPayImageView];
                //给每个图片添加一个轻拍手势
                UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapAction3:)];
                [bookPayImageView addGestureRecognizer:tap];
                [tap release];
                [bookPayImageView release];
                //NSLog(@"aaa=%@", bookPayUrl);
            }


//    // 左侧边栏开始
//    //创建拖动手势
//    UIPanGestureRecognizer* panGesture = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(panDetected:)];
//    [panGesture delaysTouchesBegan];
//    
//    [self.view addGestureRecognizer:panGesture];
    //创建抽屉视图
    self.leftVC = [[SidebarViewController alloc] init];
    self.leftVC.loginDalegate = self;
    //抽屉视图的背景颜色
    [self.leftVC setBgRGB:0x000000];
    [self.view addSubview:self.leftVC.view];
    self.leftVC.view.frame  = self.view.bounds;
    
    //创建导航栏左侧按钮
    //设置图片不被渲染
    UIImage *userImage = [UIImage imageNamed:@"iconfont-geren.png"];
    userImage = [userImage imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    //左侧按钮
    UIBarButtonItem *userBarButton = [[UIBarButtonItem alloc] initWithImage:userImage style:UIBarButtonItemStylePlain target:self action:@selector(showLeftVC:)];
    self.navigationItem.leftBarButtonItem = userBarButton;
                
                //删除动图加载
                [GiFHUD dismiss];
 }];
}];
    }];
}
//------------------------轻拍图片触发的方法---------------------------
//轻拍特价优惠上的图片后触发的方法
- (void)tapAction1:(UITapGestureRecognizer *)tap
{
    //创建将要进入的详情界面
    //取出当前轻拍的视图的tag值
    NSInteger number = tap.view.tag;
    BookSale *bookSale = [self.allSaleArray objectAtIndex:number - 1000 - 1];
    BookDetailsViewController *bookDetailsVC = [[BookDetailsViewController alloc] init];
    bookDetailsVC.title = bookSale.name;
    bookDetailsVC.nameStr = bookSale.name;
    bookDetailsVC.authornameStr = bookSale.authorname;
    bookDetailsVC.subNameStr = bookSale.subname;
    bookDetailsVC.priceStr = [NSString stringWithFormat:@"￥ :    %@",bookSale.dd_sale_price];
    bookDetailsVC.detailsImageStr = bookSale.image_url;
    bookDetailsVC.productId = bookSale.productId;
    //NSLog(@"111111111111111%@",bookSale.name);
    [self.navigationController pushViewController:bookDetailsVC animated:YES];
}
//轻拍免费阅读上的图片后触发的方法
- (void)tapAction2:(UITapGestureRecognizer *)tap
{
    //创建将要进入的详情界面
    //取出当前轻拍的视图的tag值
    NSInteger number = tap.view.tag;
    BookFree *bookFree = [self.allFreeArray objectAtIndex:number - 2001];
    BookDetailsViewController *bookDetailsVC = [[BookDetailsViewController alloc] init];
    bookDetailsVC.title = bookFree.name;
    bookDetailsVC.nameStr = bookFree.name;
    bookDetailsVC.authornameStr = bookFree.authorname;
    bookDetailsVC.subNameStr = bookFree.subname;
    bookDetailsVC.priceStr = [NSString stringWithFormat:@"￥ : 00.00"];
    bookDetailsVC.detailsImageStr = bookFree.image_url;
    bookDetailsVC.productId = bookFree.productId;
    //NSLog(@"111111111111111%@",bookFree.name);
    [self.navigationController pushViewController:bookDetailsVC animated:YES];
}
//轻拍付费阅读上的图片后触发的方法
- (void)tapAction3:(UITapGestureRecognizer *)tap
{
    //创建将要进入的详情界面
    //取出当前轻拍的视图的tag值
    NSInteger number = tap.view.tag;
    BookPay *bookPay = [self.allPayArray objectAtIndex:number - 3001];
    BookDetailsViewController *bookDetailsVC = [[BookDetailsViewController alloc] init];
    bookDetailsVC.title = bookPay.name;
    bookDetailsVC.nameStr = bookPay.name;
    bookDetailsVC.authornameStr = bookPay.authorname;
    bookDetailsVC.subNameStr = bookPay.subname;
    bookDetailsVC.priceStr = [NSString stringWithFormat:@"￥ :    %@",bookPay.price];
    bookDetailsVC.detailsImageStr = bookPay.image_url;
    bookDetailsVC.productId = bookPay.productId;
    //NSLog(@"111111111111111%@",bookFree.name);
    [self.navigationController pushViewController:bookDetailsVC animated:YES];
    
}
//-------------------------------------------------------------------
//***********************点击更多按钮触发的方法*************************
//特价优惠栏的更多按钮触发的方法
- (void)button1Action:(UIButton *)button
{
    SaleViewController *saleVC = [[SaleViewController alloc] init];
    [self.navigationController pushViewController:saleVC animated:YES];
}
//免费阅读栏的更多按钮触发的方法
- (void)button2Action:(UIButton *)button
{
    FreeViewController *freeVC = [[FreeViewController alloc] init];
    [self.navigationController pushViewController:freeVC animated:YES];
}
//付费阅读栏的更多按钮触发的方法
- (void)button3Action:(UIButton *)button
{
    PayViewController *payVC = [[PayViewController alloc] init];
    [self.navigationController pushViewController:payVC animated:YES];
}
//*****************************************************************
//设置全局变量
static int i = 1001;
//执行定时器滚屏的动画
- (void)change
{
    
    //滚动到下一张图片的位置
    self.myScrollView.contentOffset = CGPointMake(self.view.frame.size.width * (i - 1000), 0);
    i++;
    //当滚动到最后一张图片的位置时,重新滚动
    if (i == 1005) {
        i = 1001;
    }
    
}

//通过点击小点点滚动图片
- (void)pageIndexAction:(UIPageControl *)page
{
    [self.myScrollView setContentOffset:CGPointMake(self.myScrollView.frame.size.width * page.currentPage, 0) animated:YES];
}


//滑动后执行
- (void)scrollViewDidScroll:(UIScrollView *)scrollView
{
    //改变小点点的下标
    self.myPageC.currentPage = self.myScrollView.contentOffset.x / self.view.frame.size.width - 1;
}

-(void)scrollViewWillBeginDragging:(UIScrollView *)scrollView
{
    NSLog(@"将要开始拖拽的时候被触发");
    //关闭定时器
    [self.myTimer setFireDate:[NSDate distantFuture]];
}


//减速后调用
- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView
{
    //关闭定时器
    // [self.myTimer setFireDate:[NSDate distantFuture]];
    //当翻到最后一页时,即偏移量为屏幕宽度*5,跳到第二张图片的位置
    if (self.myScrollView.contentOffset.x >= self.view.frame.size.width * 5) {
        [self.myScrollView setContentOffset:CGPointMake(self.view.frame.size.width, 0) animated:NO];
    }
    //当翻到第一页时,即偏移量为0,跳到倒数第二张图片的位置
    if (self.myScrollView.contentOffset.x <= 0) {
        [self.myScrollView setContentOffset:CGPointMake(self.view.frame.size.width * 4, 0) animated:NO];
    }
    
    NSLog(@"减速结束时候被触发");
    
    //开始滑动后先让偏移量变为你滑动之后的位置,从这个新位置开始重新滚动,否则还会跳转到定时器滚动到位置
    self.myScrollView.contentOffset = CGPointMake(self.view.frame.size.width * (i - 1000 ), 0);
    i++;
    //当滚动到最后一张图片的位置时,重滚动
    if (i == 1005) {
        i = 1001;
    }
    
    //开启定时器
    [self.myTimer setFireDate:[NSDate distantPast]];
}
//左侧抽屉代理实现的方法
- (void)changeLogin
{
    LoginViewController *loginVC = [[LoginViewController alloc] init];
    [self.navigationController pushViewController:loginVC animated:YES];
    [loginVC release];
}

//拖动显示侧拉门
- (void)panDetected:(UIPanGestureRecognizer*)recoginzer
{
    [self.leftVC panDetected:recoginzer];
    
    
}
//显示和隐藏侧拉门
- (void)showLeftVC:(UIBarButtonItem *)userBarButton
{
    [self.leftVC showHideSidebar];

}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
